package com.ysqcould.web.controller.allocation;


import com.ysqcould.allocation.domain.WxRole;
import com.ysqcould.allocation.domain.WxRole;
import com.ysqcould.allocation.service.IWxRoleService;
import com.ysqcould.common.annotation.Log;
import com.ysqcould.common.core.controller.BaseController;
import com.ysqcould.common.core.domain.AjaxResult;
import com.ysqcould.common.core.page.TableDataInfo;
import com.ysqcould.common.enums.BusinessType;
import com.ysqcould.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 角色Controller
 * 
 * @author ruoyi
 * @date 2022-06-29
 */
@RestController
@RequestMapping("/allocation/role")
public class WxRoleController extends BaseController
{
    @Autowired
    private IWxRoleService wxRoleService;

    /**
     * 查询角色列表
     */
    @PreAuthorize("@ss.hasPermi('allocation:role:list')")
    @GetMapping("/list")
    public TableDataInfo list(WxRole wxRole)
    {
        startPage();
        List<WxRole> list = wxRoleService.selectWxRoleList(wxRole);
        return getDataTable(list);
    }

    /**
     * 导出角色列表
     */
    @PreAuthorize("@ss.hasPermi('allocation:role:export')")
    @Log(title = "角色", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WxRole wxRole)
    {
        List<WxRole> list = wxRoleService.selectWxRoleList(wxRole);
        ExcelUtil<WxRole> util = new ExcelUtil<WxRole>(WxRole.class);
        util.exportExcel(response, list, "角色数据");
    }

    /**
     * 获取角色详细信息
     */
    @PreAuthorize("@ss.hasPermi('allocation:role:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(wxRoleService.selectWxRoleById(id));
    }

    /**
     * 新增角色
     */
    @PreAuthorize("@ss.hasPermi('allocation:role:add')")
    @Log(title = "角色", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WxRole wxRole)
    {
        wxRole.setAsId(getUserId());
        return toAjax(wxRoleService.insertWxRole(wxRole));
    }

    /**
     * 修改角色
     */
    @PreAuthorize("@ss.hasPermi('allocation:role:edit')")
    @Log(title = "角色", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WxRole wxRole)
    {
        return toAjax(wxRoleService.updateWxRole(wxRole));
    }

    /**
     * 删除角色
     */
    @PreAuthorize("@ss.hasPermi('allocation:role:remove')")
    @Log(title = "角色", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wxRoleService.deleteWxRoleByIds(ids));
    }

    /**
     * 状态修改
     */
    @Log(title = "通信录", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody WxRole role)
    {
        return toAjax(wxRoleService.updateStatus(role));
    }

    /**
     * 状态修改
     */
    @Log(title = "通信录", businessType = BusinessType.UPDATE)
    @PutMapping("/changeIsDefaultStatus")
    public AjaxResult changeIsDefaultStatus(@RequestBody WxRole role)
    {
        return toAjax(wxRoleService.changeIsDefaultStatus(role));
    }

    /**
     * 状态修改
     */
    @Log(title = "通信录", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatementStatus")
    public AjaxResult changeStatementStatus(@RequestBody WxRole role)
    {
        return toAjax(wxRoleService.changeStatementStatus(role));
    }

    /**
     * 状态修改
     */
    @Log(title = "通信录", businessType = BusinessType.UPDATE)
    @PutMapping("/changeContactsStatus")
    public AjaxResult changeContactsStatus(@RequestBody WxRole role)
    {
        return toAjax(wxRoleService.changeContactsStatus(role));
    }

    /**
     * 状态修改
     */
    @Log(title = "通信录", businessType = BusinessType.UPDATE)
    @PutMapping("/changeTypeStatus")
    public AjaxResult changeTypeStatus(@RequestBody WxRole role)
    {
        return toAjax(wxRoleService.changeTypeStatus(role));
    }
}
